﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.IO;

using System.Web.UI.WebControls;

using Module.DataAccess;
using Module.EntitiesInfo;


namespace Module.BusinessLogic
{
    public class CMSVideoClipBL
    {
        
        public static int Insert(CMSVideoClipInfo cmsVideoClipInfo)
        {
            try
            {
                DataCach.DataCach cache = new DataCach.DataCach();
                cache.RemoveAll();
                return new CMSVideoClipDB().Insert(cmsVideoClipInfo);
            }
            catch (Exception ex)
            {
                throw;
            }

        }


        public static void Update(CMSVideoClipInfo cMSVideoClipInfo)
        {
            try
            {
                new CMSVideoClipDB().Update(cMSVideoClipInfo);
                DataCach.DataCach cache = new DataCach.DataCach();
                cache.RemoveAll();
            }
            catch (Exception ex)
            {
                throw;
            }

        }
        
        public static void Delete(int zoneID)
        {
            try
            {
                new CMSVideoClipDB().Delete(zoneID);
                DataCach.DataCach cache = new DataCach.DataCach();
                cache.RemoveAll();
            }
            catch (Exception ex)
            {
                throw;
            }

        }

        public static CMSVideoClipInfo GetInfo(int type, string param_1, string param_2)
        {
            try
            {
                return ObjectHelper.FillObject<CMSVideoClipInfo>(new CMSVideoClipDB().Select(type, param_1, param_2));
            }
            catch (Exception ex)
            {
                throw;
            }
        }

        public static List<CMSVideoClipInfo> Select(int type, string param_1, string param_2)
        {
            try
            {
                return ObjectHelper.FillCollection<CMSVideoClipInfo>(new CMSVideoClipDB().Select(type, param_1, param_2));
            }
            catch (Exception ex)
            {
                throw;
            }
        }
        public static List<CMSVideoClipInfo> Select(int type, string param_1)
        {
            try
            {
                return ObjectHelper.FillCollection<CMSVideoClipInfo>(new CMSVideoClipDB().Select(type, param_1));
            }
            catch (Exception ex)
            {
                throw;
            }
        }
        public static List<CMSVideoClipInfo> Select(int type)
        {
            try
            {
                return ObjectHelper.FillCollection<CMSVideoClipInfo>(new CMSVideoClipDB().Select(type));
            }
            catch (Exception ex)
            {
                throw;
            }
        }

  
        public static DataTable SelectTbl(int? type, string para_1, string para_2)
        {
            try
            {
                return new CMSVideoClipDB().SelectTbl(type, para_1, para_2);
            }
            catch (Exception ex)
            {
                throw;
            }
        }

        public static DataTable SelectTbl(int? type, string para_1)
        {
            try
            {
                return new CMSVideoClipDB().SelectTbl(type, para_1);
            }
            catch (Exception ex)
            {
                throw;
            }
        }
        public static DataTable SelectTbl(int? type)
        {
            try
            {
                return new CMSVideoClipDB().SelectTbl(type);
            }
            catch (Exception ex)
            {
                throw;
            }
        }     
        public static int GetCount(string keysearch, int zoneId,int status, DateTime starDatetime, DateTime endDatetime, int beginRow, int endRow)
        {
            try
            {
                return new CMSVideoClipDB().GetCount(keysearch, zoneId,status,starDatetime, endDatetime, beginRow, endRow);
            }
            catch (Exception ex)
            {
                throw;
            }

        }

        public static DataTable Search(string keysearch, int zoneId,int status, DateTime starDatetime, DateTime endDatetime, int beginRow, int endRow, string orderByColumn)
        {
            try
            {
                return new CMSVideoClipDB().Search(keysearch, zoneId,status,starDatetime, endDatetime, beginRow, endRow, orderByColumn);
            }
            catch (Exception ex)
            {
                throw;
            }

        }
        public static void UpdateStatus(int videoId, int status, int param)
        {
            try
            {
                new CMSVideoClipDB().UpdateStatus(videoId, status, param);
            }
            catch (Exception ex)
            {
                throw;
            }

        }

        public static DataTable GetTop()
        {
            try
            {
                DataCach.DataCach cache = new DataCach.DataCach();
                string strCache = "{D1356DF3-D2C6-4DBD-AC95-34879DF679C1}";
                DataTable dt = new DataTable();
                if (cache.GetCache(strCache) != null)
                {
                    dt = (DataTable)(cache.GetCache(strCache));
                    return dt;
                }
                dt = new CMSVideoClipDB().GetTop();
                if (dt != null && dt.Rows.Count > 0)
                {
                    cache.InsertCache(strCache, dt, Convert.ToDouble(ConfigurationSettings.AppSettings["timeCache"].ToString()));
                }
                return dt;                 
            }
            catch (Exception ex)
            {
                throw;
            }

        }

        public static CMSVideoClipInfo GetInfoOutSite(int type, string param_1, string param_2)
        {
            try
            {
                DataCach.DataCach cache = new DataCach.DataCach();
                string strCache = type + "_" + param_1 + "_" + param_2 + "_" + "{D7982C49-048B-4FC2-B945-122F3F878721}";
                CMSVideoClipInfo info = new CMSVideoClipInfo();
                if (cache.GetCache(strCache) != null)
                {
                    info = (CMSVideoClipInfo)(cache.GetCache(strCache));
                    return info;
                }
                info =ObjectHelper.FillObject<CMSVideoClipInfo>(new CMSVideoClipDB().Select(type, param_1, param_2));
                if (info != null)
                {
                    cache.InsertCache(strCache, info, Convert.ToDouble(ConfigurationSettings.AppSettings["timeCache"].ToString()));
                }
                return info;  
               
            }
            catch (Exception ex)
            {
                throw;
            }
        }

    }
}